package info.douyi.dps.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import info.douyi.dps.mapper.PestMapper;
import info.douyi.dps.model.Pest;
import info.douyi.dps.model.PestExample;
import info.douyi.dps.service.SelectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SelectServiceImpl implements SelectService {

    private static final Logger logger = LoggerFactory.getLogger(SelectServiceImpl.class);

    @Autowired
    private PestMapper pestMapper;


    @Override
    public PageInfo<Pest> selectPestByKeywordAndPage(String keyword, int pageNum, int pageSize) {
        PestExample example = new PestExample();
        PestExample.Criteria criteria = example.createCriteria();
        criteria.andNamezhcnLike("%" + keyword + "%");
        PestExample.Criteria criteria1 = example.createCriteria();
        criteria1.andSynonymsLike("%"+keyword + "%");
        PageHelper.startPage(pageNum, pageSize);
        List<Pest> pests = pestMapper.selectByExample(example);
        return PageInfo.of(pests);
    }
}
